﻿using System;
using System.Collections.Generic;
using System.Text;

namespace daSyntaxAnalyser.SyntaxTree
{
    using daBase.Objects;

    public class CaseStatementElement : StatementElement
    {
        private ExpressionElement expression;
        private List<StatementElement> cases;

        public ExpressionElement Expression { get { return expression; } set { expression = value; } }
        public List<StatementElement> Cases { get { return cases; } set { cases = value; } }

        public CaseStatementElement(TokenInfo StartInfo, ExpressionElement Expression, List<StatementElement> Cases, List<TokenInfo> Comments)
            : base(StartInfo, Comments)
        {
            expression = Expression;
            cases = Cases;
        }

        public override string ToString()
        {
            string result = ((cases != null) && (cases.Count > 0)) ? string.Format("{0};", Tabulate(cases.Join(";\r\n"))) : string.Empty;
            return string.Format("case {0} of\r\n{1}\r\nend", expression, result);
        }

        protected override IEnumerator<ISyntaxTreeElement> CreateEnumerator()
        {
            yield return expression;
            if (cases != null)
                foreach (StatementElement _case in cases)
                    yield return _case;
        }
    }
}
